<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<script type="text/javascript" src="<%=basePath%>Js/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/mycss/bootstrap.min.css" />
        <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
		<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
		<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<head>
<meta charset="UTF-8">
</head>
<script type="text/javascript">

//通过房间号查询房间动态
function selectRoomByNumber(){
	var roomNumber = $("#roomNumber").val();
	if (!(/(^[0-9]*[1-9][0-9]*$)/.test(roomNumber))){
		alert("你的输入带有字符");
	}else{
		$.ajax({
			type:"post",
			url:"selectRoomByNumber.do",
			data:{
				"roomNumber":roomNumber,
			},
			success:function(result){
				stus = JSON.parse(result)
				for(var i = 0; i < stus.length; i++ ){
					var stu = "";
					stu += "<tr><th>房间号</th><th>楼层</th><th>价格</th><th>房型</th> <th>状态</th><th>容纳人数</th><th>备注</th><th>操作</th></tr>";
					stu += "<tr><td>"+stus[i].roomnum+"</td><td>"+stus[i].floor+"</td><td>"+stus[i].price+"</td>";
					stu += "<td>"+stus[i].type+"</td> <td>"+stus[i].status+"</td><td>"+stus[i].quantity+"</td><td>"+stus[i].remark+"</td>";
					stu +="<td>"
					if(stus[i].status == "空闲"){
						stu +="<a href='' onclick=''>预约</a>"
					}
					
					stu +="</td></tr>"
					
					$("#page1").remove();
					$("#roomTable").empty();
					$("#roomTable").html(stu);
				}
				
			},
			error:function(){
				
			}
		})
	}
}

//通过楼层、房间动态、房型条件查询房间信息
function selectRoomByother(){
	
	var floor = $("#floor").find("option:selected").text();
	var state = $("#state").find("option:selected").text();
	var houseType = $("#houseType").find("option:selected").text();
	
	if(floor =="默认" && state=="默认" && houseType=="默认"){
		window.location.href="queryRoom3.do";
	}else{
		window.location.href="selectRoomByother3.do?floor="+floor+"&state="+state+"&houseType="+houseType;
	}
	
	

}

//刷新
function refreshPage(){
	window.location.href="queryRoom3.do";
}

function subscribeRoom(roomNumber){
	
	$.ajax({
		type:"post",
		url:"subscribeRoom.do",
		data:{
			"roomNumber":roomNumber,
		},
		success:function(result){
			if(result=="1"){
				alert("预约成功")
			}else{
				alert("预约失败")
			}
		},
		error:function(){
			alert("系统故障")
		}
	})
	
}


</script>

<body>

<h3 align="center">客房动态查询</h3>

<table >
<tr><td><input type="text" name="roomNumber" id="roomNumber" class="form-control" placeholder="请输入房间号" value=""></td>
<td>&nbsp;&nbsp;<button class="btn btn-primary" onclick="selectRoomByNumber()">查询</button>&nbsp;&nbsp; </td>
</tr>
</table>
  <br>
<div>


		<table>
			<tr>
			<td>选择楼层：</td>	
				<td>
                <select name="floor" id="floor" class="form-control">

						<option value="0">默认</option>
						<c:forEach items="${floorlist}" var="floorlist">

						<option value="1">${floorlist.floor}</option>
						</c:forEach>

				</select>
				</td>
				
				<td>选择房型：</td>	
					<td>&nbsp;&nbsp;
				<select name="houseType" id="houseType" class="form-control">
				
				  <option value="0">默认</option>
				  
				  <c:forEach items="${houselist}" var="list">
	              <option value="0">${list.housetype}</option>
	              </c:forEach>
	           </select><br> 
				</td>
				
				<td>&nbsp;&nbsp;<button class="btn btn-primary" onclick="selectRoomByother()">查询</button>&nbsp;&nbsp; </td>
				<td>&nbsp;&nbsp;<button class="btn btn-success" onclick="refreshPage()">刷新</button>&nbsp;&nbsp; </td>
			</tr>
		</table>
		  
    
</div><br>

<table class="table table-hover" id="roomTable">

<tr><th>房间号</th><th>楼层</th><th>价格</th><th>房型</th> <th>状态</th><th>容纳人数</th><th>备注</th><th>操作</th></tr>
<c:forEach items="${pageInfo.list}" var="roomlist">

<tr>
<td>${roomlist.roomnum}</td><td>${roomlist.floor}</td><td>${roomlist.price}</td>
<td>${roomlist.type}</td> <td>${roomlist.status}</td><td>${roomlist.quantity}</td>
<td>${roomlist.remark}</td>
<td>
<c:if test="${roomlist.status == '空闲' }">
<a href="" data-toggle="modal" data-target="#myModal" onclick="subscribeRoom('${roomlist.roomnum}')">预约</a>
</c:if>
</td>
</tr>

</c:forEach>
</table>

         <c:if test="${inf eq null}">
		<div id="page1">
	<c:if test="${!pageInfo.isFirstPage && !empty pageInfo}">
					<a href="${pageContext.request.contextPath }/queryRoom3.do">首页</a>
					<a href="${pageContext.request.contextPath }/queryRoom3.do?pageNum=${pageInfo.prePage}">上一页</a>
				</c:if>
				<c:if test="${!pageInfo.isLastPage }">
				<a href="${pageContext.request.contextPath }/queryRoom3.do?pageNum=${pageInfo.nextPage}">下一页</a>
				<a href="${pageContext.request.contextPath }/queryRoom3.do?pageNum=${pageInfo.lastPage}">末页</a>
				</c:if>
				当前页：${pageInfo.pageNum }/${pageInfo.pages }.
				</div>
				</c:if>
				
		<c:if test="${!(inf eq null)}">
		<div id="page1">
	<c:if test="${!pageInfo.isFirstPage && !empty pageInfo}">
					<a href="${pageContext.request.contextPath }/selectRoomByother3.do?floor=${floor}&state=${state}&houseType=${houseType}">首页</a>
					<a href="${pageContext.request.contextPath }/selectRoomByother3.do?pageNum=${pageInfo.prePage}&floor=${floor}&state=${state}&houseType=${houseType}">上一页</a>
				</c:if>
				<c:if test="${!pageInfo.isLastPage }">
				<a href="${pageContext.request.contextPath }/selectRoomByother3.do?pageNum=${pageInfo.nextPage}&floor=${floor}&state=${state}&houseType=${houseType}">下一页</a>
				<a href="${pageContext.request.contextPath }/selectRoomByother3.do?pageNum=${pageInfo.lastPage}&floor=${floor}&state=${state}&houseType=${houseType}">末页</a>
				</c:if>
				当前页：${pageInfo.pageNum }/${pageInfo.pages }.
				</div>
				</c:if>
				
				
				
	
						<!-- 模态框（Modal） -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
					</div>
					<div id="myModalLabel">
					
					</div>
					<div class="modal-body" id="Inf">
						
					</div>
				
					   <div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭
						</button>
					
					</div>
				</div><!-- /.modal-content -->
			</div><!-- /.modal -->
		</div>

                  

</body>
</html>